console.log('======注册全局方法')
import stores from '@/stores'
import { Toast } from 'vant'

/* 加载 */
Vue.prototype.$loading = function() {
  Toast.loading({
    duration: 0
  })
}
Vue.prototype.$loadingHide = function() {
  Toast.clear()
}

/* 轻提示 */
Vue.prototype.$success = function(msg = '', mask = false, duration = 2000) {
  Toast.success({
    message: msg,
    forbidClick: mask,
    duration
  })
}
Vue.prototype.$fail = function(msg = '', mask = false, duration = 2000) {
  Toast.fail({
    message: msg,
    forbidClick: mask,
    icon: 'cross',
    duration
  })
}
Vue.prototype.$msg = function(msg = '', mask = false, duration = 2000) {
  Toast({
    message: msg,
    forbidClick: mask,
    duration
  })
}

/**
 * 获取对应桶state值
 * @param {String} name 存储桶名称
 * @param {String} key key值
 */
Vue.prototype.$getState = function(name, key) {
  // eslint-disable-next-line no-prototype-builtins
  if (stores.state.hasOwnProperty(name) && stores.state[ name ].hasOwnProperty(key)) {
    return stores.state[ name ][ key ]
  }
  return ''
}

/**
 * 获取对应桶getter值
 * @param {String} name getters名
 */
Vue.prototype.$storesGet = function(name) {
  // eslint-disable-next-line no-prototype-builtins
  if (stores.getters.hasOwnProperty(name)) {
    return stores.getters[ name ]
  }
  return ''
}

/**
 * commit方法
 * @param {String} name 方法名
 * @param {Any} params 参数
 */
Vue.prototype.$storesCommit = function(name, params) {
  stores.commit(name, params)
}
